home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #21 (Jun 87) / IconApp source / IconApp.Asm < prev    next >
Assembly Source File  |  1987-05-13  |  7KB  |  248 lines

  1.  
  2. ;IconApp
  3.  
  4.     Include    MacTraps.D
  5.     Include    SysEqu.D
  6.     Include    PackMacs.Txt
  7.  
  8. ;------------------------------Macros-----------------
  9. ; IconDraw assumes that D5 contains the total number
  10. ; of resources of type 'ICN#' in the application, and
  11. ; D6 is an index to the icon we are going to plot next.
  12. ; A0-> the sourcerect,A1-> the destrect and 
  13. ; D0-> the number of bytes to transfer.
  14.  
  15. MACRO    IconDraw    IRect    =
  16.     clr.l    -(SP)        ;handle
  17.     move.L    #'ICN#',-(SP)    ;res type
  18.     move    D6,-(SP)    ;index
  19.     _GetIndResource
  20.     move.l    (SP),A0    
  21.     movea.l    (A0),A0        ;handle to ptr
  22.     cmpa.l    #0,A0        ;nil?
  23.     beq    CloseRez    ;yes, so exit
  24.     lea    iconmap,A1    
  25.     movea.l    (A1),A1        
  26.     move.l    #128,D0        
  27.     _BlockMove          ;copy icon res to iconmap
  28.     pea    {IRect}
  29.     lea    iconmap,A1    ;get icon handle
  30.     move.l    A1,-(SP)
  31.     _PlotIcon        ;plot icon in rect
  32.     |
  33.     
  34. MACRO    CheckDItem    Item    =
  35.     move.l    (A2),-(SP)        ; get Dialog pointer
  36.     move.w    {Item},-(SP)        ; Dialog item in question
  37.     pea    theType(A5)        ; VAR type
  38.     pea    theItem(A5)        ; VAR item
  39.     pea    theRect(A5)        ; VAR box
  40.     _GetDItem
  41.     |
  42. XDEF    START            ; linker requisite
  43. ;-------------------Equates----------------------
  44. AllEvents    equ    $0000FFFF
  45. DWindLen    equ    $AA
  46. ;-------------------Initialize Managers-----------
  47. START
  48.         pea     -4(A5)        ; push Quickdraw globals
  49.         _InitGraf        ; init Quickdraw 
  50.         _InitFonts          ; init Font manager
  51.         _InitWindows        ; init Window manager
  52.         _InitMenus           ; init Menu manager
  53.         clr.l        -(SP)     ; no restart procedure 
  54.         _InitDialogs        ; init Dialog manager
  55.         _TEInit            ; init TextEdit 
  56.         move.l    #AllEvents,D0   ; all standard events
  57.         _FlushEvents        ; flushed from event queue
  58.         _InitCursor        ; get standard arrow cursor
  59. ;--------------------------Miscellaneous------------------
  60.         move.l    #128,D0        ; 128 bytes for icon
  61.         _NewPtr            ; get pointer 
  62.         cmpi    #0,D0        ; error?
  63.         Bne    Quit        ; yes, exit out
  64.         lea    iconmap,A1    ; no, get handle to icon
  65.         move.l    A0,(A1)        ; save pointer to icon data
  66.         move.L    #'ICON',-(SP)    ; res type for icon
  67.         move    #128,-(SP)    ; ResID of our generic icon
  68.         _GetResource        ; get generic icon from system
  69.         move.l    (SP),A4        ; save its handle in A4
  70.         bra    IconInfo    ; get IconDialog box
  71. Quit
  72.         _ExitToShell
  73. ;------------------------------------------------------------------
  74. IconInfo
  75.         clr.l    -(SP)        ; get room for Dialog pointer
  76.         move.w    #160,-(SP)    ; resource ID
  77.         pea    IconDialog(A5)    ; storage for Dialog record
  78.         move.l    #-1,-(SP)    ; in front of other windows
  79.         _GetNewDialog
  80.         lea    IconHandle,A2    ; duplicate handle
  81.         move.l    (SP),(A2)    ; leave handle on stack 
  82.         _DrawDialog        ; draw dialog box and..
  83.         lea    IconHandle,A2
  84.         move.l    (A2),-(SP)    ; set port to us
  85.         _SetPort
  86. DialogLoop
  87.         bsr    Outline        ; outline the 'quit' button
  88.         bsr    GetFrames    ; draw our three icon frames
  89.         clr.l    -(SP)        ; no filter proc
  90.         pea    ItemHit        ; VAR ItemHit
  91.         _ModalDialog
  92.         move    ItemHit,D0    ; Get Item chosen
  93.         cmp.b    #1,D0        ; quit?
  94.         beq.s    CloseIt
  95.         cmp.b    #2,D0        ; get appl. icon?
  96.         beq.s    GetFile
  97.         bra    DialogLoop    ; no,wait for a  valid choice
  98. CloseIt
  99.         move.l    (A2),-(SP)    ; get dialog ptr.
  100.         _CloseDialog        ; close dialog
  101.         _ExitToShell        ; exit...
  102. GetFile
  103.         move.w    #100,-(sp)    ; upper corner of reply box 
  104.         move.w    #100,-(sp)
  105.         pea    scratch        ; dummy string
  106.         clr.l    -(sp)        ; filter
  107.         move    #1,-(sp)    ; only applications
  108.         pea    apptype        ; type list
  109.         clr.l    -(sp)        ; dialog hook
  110.         pea    appreply    ; reply record
  111.         move    #2,-(sp)    ; standard file reply dialog
  112.         _pack3
  113.         move     rgood+appreply,d0    ; was a file chosen?
  114.         beq    DialogLoop        ; no, return
  115.         lea    parmblock(A5),A0    ; A0-> parameter block
  116.         clr.l    ioCompletion(A0)    ; no completion routine
  117.         lea    appreply,A1        ; A1-> reply record
  118.         move.w    6(A1),ioVRefNum(A0)    ; get drive refnum
  119.         clr.l    ioVNPtr(A0)        ; volume name pointer
  120.         _SetVol        
  121. SearchIcon
  122.         clr    -(SP)    ; room for resource file ref num
  123.         lea    rname+appreply,A1    ; get filename
  124.         move.l    A1,-(SP)
  125.         _OpenResFile            ; open resource file 
  126.         move    (SP),D7            ; D7=refnum
  127.         cmpi    #-1,D7            ; error?(no resources)
  128.         Bne    ValidName        ; no,get filename
  129.         bra    NoRez            ; yes,beep and return
  130. NoRez
  131.         move    #20,-(SP)
  132.         _SysBeep
  133.         bra    DialogLoop
  134. ValidName
  135.         CheckDItem    #3        ; get statictext handle
  136.         move.l    theItem(A5),-(SP)     
  137.         pea    rname+appreply        ; get our filename
  138.         _SetIText            ; print it in dialog
  139.         clr    -(SP)            ; room for # of icons
  140.         move.L    #'ICN#',-(SP)        ; resource type
  141.         _CountResources 
  142.         move    (SP),D5        ; get # of icons in file
  143.         subq    #2,D5
  144.         cmpi    #1,D5        ; is there at least one icon?
  145.         blt    NoIcon        ; no, say so
  146.         bra    DoIcon        ; otherwise,prepare to plot it
  147. DoIcon
  148.         move    #1,D6        ; get first icon
  149.         IconDraw    iconrect1    ; plot it
  150.         cmp        D5,D6        ; is this the only icon?
  151.         beq    CloseRez    ; yes,close resource file
  152.         addq    #1,D6        ; no,add one to counter
  153.         bra    DoIcon2        ; get second icon
  154. DoIcon2
  155.         IconDraw    iconrect2    ; plot second icon
  156.         cmp    D5,D6        ; is there a third icon?
  157.         beq    CloseRez    ; no, close resource file
  158.         addq    #1,D6        ; yes, add one to counter
  159.         bra    DoIcon3        ; get third icon
  160. DoIcon3
  161.         IconDraw    iconrect3    ; plot third icon
  162.         bra    CloseRez    ; close resource file
  163. NoIcon
  164.         CheckDItem    #3        ; get statictext handle
  165.         move.l    theItem(A5),-(SP)     
  166.         pea    rname+appreply        ; get our filename
  167.         _SetIText            ; print it in dialog
  168.         move.l    A4,A0        ; get handle of generic icon
  169.         movea.l    (A0),A0        ; A0-> sourcerect
  170.         cmpa.l    #0,A0
  171.         beq    CloseRez
  172.         lea    iconmap,A1    ; A1-> destrect    
  173.         movea.l    (A1),A1
  174.         move.l    #128,D0        ; D0 = number of bytes to move    
  175.         _BlockMove  
  176.         pea    iconrect1
  177.         lea    iconmap,A1
  178.         move.l    A1,-(SP)
  179.         _PlotIcon        ; plot generic icon
  180.         bra    DialogLoop    ; return
  181. GetFrames
  182.                     ; print icon frames
  183.         pea    iconframe1
  184.         _FrameRect 
  185.         pea    iconframe2
  186.         _FrameRect 
  187.         pea    iconframe3
  188.         _FrameRect 
  189.         rts
  190. OutLine
  191.             ; outline first item in dialog, or 'quit' button
  192.         CheckDItem    #1
  193.         move    #3,-(SP)
  194.         move    #3,-(SP)
  195.         _PenSize
  196.         pea    theRect(A5)        ; VAR box
  197.         move    #-4,-(SP)
  198.         move    #-4,-(SP)
  199.         _InsetRect
  200.         pea    theRect(A5)
  201.         move    #16,-(SP)
  202.         move    #16,-(SP)
  203.         _FrameRoundRect
  204.         rts
  205. CloseRez
  206.         move    D7,-(SP)    ; D7=rsrc.file refnum
  207.         _CloseResFile        ; close resource file
  208.         bra    DialogLoop    ; return 
  209.         
  210. ;----------------------Local storage-------------------
  211. EventRecord
  212.     
  213.     What:        dc.w    0    ;what event number
  214.     Message:    dc.l    0    ;ptr. to msg
  215.     When:        dc.l    0    ;Time event was posted
  216.     Point:        dc.l    0    ;mouse coordinates
  217.     Modify:        dc.w    0    ;state of keys & button
  218.     
  219.     WWindow:    dc.l    0    ;Find window's result
  220.     
  221. IconHandle        dc.l    0
  222. ItemHit            dc.w    0    ; dialog items
  223. scratch    
  224.             dc.b    14
  225.             dc.b    ''
  226.             dc.l    0
  227. apptype            dc.b    'APPL'
  228.             dcb.b    14,$ff
  229. appreply        dc.w    5
  230.             dc.b    63
  231.             dcb.b    63,0
  232.             
  233. iconmap           dc.w    0,0,4,0,0,$20,$20
  234. iconrect1        dc.w    17,61,49,93
  235. iconrect2        dc.w    17,120,49,152
  236. iconrect3        dc.w    17,174,49,206 
  237. iconframe1        dc.w    10,57,54,98
  238. iconframe2        dc.w    10,115,54,156
  239. iconframe3        dc.w    10,169,54,210
  240.  
  241. ;----------------------Globals-----------------
  242. IconDialog        ds.w    DWindLen
  243. theType            ds.w    1        ; VAR for GetDItem
  244. theItem            ds.l    1        ; VAR for GetDItem
  245. theRect            ds.w    4        ; VAR for GetDItem
  246. parmblock        ds.w    80
  247.  
  248.